n = input()
max =0
if len(n) != 4:
    pass
else:
    d = list(n)
    
    for t in range(0, 3):
        for i in range(2,int(d[t]+d[t+1])): 
            if int(d[t]+d[t+1]) % i == 0:
                break 
        else:
            if int(d[t]+d[t+1])>max:
                max = int(d[t]+d[t+1])
    for k in d:
        for i in range(2, int(k)):
            if int(k) % i == 0:
                break
        else:
            if int(k)>max: 
                max=int(k)
    for i in range(2, int(n)):
        if int(n)%i == 0:
            break
    else:
        if max< int(n):
            max = int(n)
    for z in range(1,3):
        for i in range(2,int(d[z-1]+d[z]+d[z+1])): 
            if int(d[z-1]+d[z]+d[z+1]) % i == 0:
                break
        else:
            if int(d[z-1]+d[z]+d[z+1])>max: 
                max = int(d[z-1]+d[z]+d[z+1])

print(max)


